﻿@model TDT.Land.Entity.Pro_Building
@{
    ViewBag.Title = Model.BuildingName;
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@*<script src="../../Scripts/editor/adapters/jquery.js" type="text/javascript"></script>*@
<script src="../../Scripts/editor/ckeditor.js" type="text/javascript"></script>
@section HeaderContent{
    <script type="text/javascript">
        function openNew() {
            var dt = new Date();
            var href = "/admin/openEditNews?id=&dt=" + dt.getTime();
            $("#popup_content").load(href);
            showPopup('Insert product...');
        }


        function DoSave() {
            var arrFied = new Array("BuildingName", "Code");
            if (validateNotNull(arrFied))
                $("#Building").submit();
        }


        function cancel() {
            window.location.assign("/building/ManagerNews");
        }

        $(document).ready(function () {
            // Handler for .ready() called.

        });


        $(function () {
            $("#Building").ajaxForm({
                iframe: true,
                dataType: "json",
                beforeSubmit: function () {
                    // su kien truoc khi up image
                },
                success: function (result) {
                    cusAlert("Lưu thành công!");
                    window.location.assign("/building/ManagerNews");
                },
                error: function (xhr, textStatus, errorThrown) {
                    cusAlert("Có lỗi xảy ra trong quá trình lưu dữ liệu... Vui lòng liên hệ quản trị viên");
                }
            });
        });

        function SetAltValue(value) {       
        var _value = change_alias(value);
            $("#Code").val(_value);
        }

        function change_alias(alias) {
            var str = alias;
            str = str.toLowerCase();
            str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ |ặ|ẳ|ẵ/g, "a");
            str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
            str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
            str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ |ợ|ở|ỡ/g, "o");
            str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
            str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
            str = str.replace(/đ/g, "d");
            str = str.replace(/!|@@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g, "-");
            /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */
            str = str.replace(/-+-/g, "-"); //thay thế 2- thành 1-
            str = str.replace(/^\-+|\-+$/g, "");
            //cắt bỏ ký tự - ở đầu và cuối chuỗi
            return str;
        }

    </script>
}
@section Toolbar {
    <a class="btn_boder btn_save" onclick="DoSave()">Save</a> 
    <a class="btn_boder btn_cancel" onclick="cancel()"> Cancel</a>
}

<div>
   
@*@using (Html.BeginForm("doSave", "Building", FormMethod.Post, new { enctype = "multipart/form-data", id = "fpos" }))
{ *@
    
        <form action="/building/doSave" method="post" enctype="multipart/form-data" id="Building">
        @Html.Hidden("BuildingType", CategoryType.W_NEW_TYPE)
        
      <table cellpadding="0" cellspacing="0" class="tbEdit">
        <tr>
            <th>
                Tiêu đề bài viết <span class="sp_batBuoc">(*)</span>
            </th>
            <td>@Html.TextBoxFor(p => p.BuildingName, new { onkeyup = "SetAltValue(this.value);" })
            </td>
        </tr>
        <tr>
            <th>Alt <span class="sp_batBuoc">(*)</span></th>
            <td>
                @Html.TextBoxFor(p => p.Code)
            </td>
        </tr>
        <tr>
            <th>
                Hiển thi Home
            </th> 
            <td>
                @{
                    bool isShowHome = Model.IsSlideShow.ToString() == "True" ? true : false ;                    
                 }

                  @Html.CheckBox("IsSlideShow", isShowHome, Model.IsSlideShow)
                 
            </td>
        </tr>  

        <tr>
            <th>            
                Image
            </th>
            <td>   
                <div>
                   @{
                       if(!string.IsNullOrEmpty(Model.ImageFile)){
                           <img alt="" src="../Uploads/@Model.ImageFile" width="150px;" />
                       }
                       }
                </div>         
                <div>
                    <input type="file" name="fileName" id="fileName" />
                </div>
            </td>
        </tr>
        @*<tr>
            <th>
                Mô ta ngan
            </th>
            <td>
            
            @Html.TextAreaFor(p => p.ShortDescription)            
            </td>
        </tr>*@
        <tr>
            <th colspan="2">
                Chi tiet
            </th>
        </tr>
        <tr>
            <td colspan="2">
                @* @Html.Hidden("Description", info.Description)*@
                @Html.TextAreaFor(a => a.Description)

                <script>
                    var editor = CKEDITOR.replace('Description');
                    //                    CKEDITOR.replace('Description');
                </script>
                @*  @Html.Partial("UC_CuteEditor")*@
            </td>
        </tr>
    </table>
    @Html.Hidden("ID", Model.ID)
    @Html.Hidden("ImageFile", Model.ImageFile)
    
    </form>

   @* }*@
</div>


